﻿using System;
using NHibernate;
using YunBox2.Contracts.Core;

namespace YunBox2.Server.Core
{
	public class PermissionBiz : BizBase<Permission>
	{
		public PermissionBiz(ISession session, User user)
			: base(session, user)
		{
		}

		public Permission Get(Guid userId,Guid moduleId)
		{
			var permission = Session.QueryOver<Permission>().Where(x =>  x.OwnerID == userId && x.ModuleID == moduleId ).SingleOrDefault();
			if(permission==null)
			{
				permission = new Permission() {Approve = false, Audit = false, Edit = false, Extensions = "<permission/>", Id = Guid.Empty, Invalid = false, ModuleID = moduleId, OwnerID = userId, Print = false, Remove = false};
			}
			return permission;
		}
	}
}